/**
 * Created by wd on 2017/3/7.
 */
$(function(){
    //初始化一二级分类
    ajax('{{$category_one->id}}');
    //根据一级分类获取二级分类
    $("#setTwo").change(function(){
        var _id = $("#setTwo").val();
        ajax(_id);
    });



    //ajax获取二级分类
    function ajax(_id){
        $.ajax({
            url: '/product/getTwo',
            type: "GET",
            data: {parent_id:_id},
            dataType: "json",
            success: function(data) {
                console.log(data);
                if(data.code == 100) {
                    $('#category_two').empty();
                    var html = '';
                    for(var i=0;i<data['category_two'].length;i++){
                        html+='<option value='+data['category_two'][i]['id']+'>'+data['category_two'][i]['name']+'</option>';
                    }
                    $('#category_two').html(html);
                }else{
                    layer.msg(data.msg);
                }
            },
            error:function(){
                layer.msg('error');
            }
        });
    }
});